window.EtUtils = (function () {
  return {
    type: WpsClientTypeEnum.表格,

    /**
     * @returns {Et.EtWorkbook}
     */
    getActiveDto() {
      return wps.ActiveWorkbook;
    },

    /**
     * @returns {Et.EtWorkbooks}
     */
    getWorkDtos() {
      return wps.EtApplication().Workbooks;
    },

    /**
     * 读取单元格数据
     */
    readCellData(row, col) {
      // 获取当前工作表
      let sheet = this.getActiveDto().ActiveSheet;
      return sheet.Cells.Item(row, col).Value2;
    },

    readRowData(rowIndex, colCount) {
      // 创建一个数组来存储该行的数据
      let rowData = [];

      // 遍历该行的每一列，读取数据
      for (let i = 1; i <= colCount; i++) {
        rowData.push(this.readCellData(rowIndex, i));
      }
      return rowData;
    },

    getAllData(maxRow, maxCol) {
      const allData = [];
      for (let i = 1; i <= maxRow; i++) {
        allData.push(this.readRowData(i, maxCol));
      }
      return allData;
    },

    /**
     * 获取选区
     */
    getSelection(){
      return Application.Selection;
    },

    writeTextToCell(row, col, text) {
      // 获取当前工作表
      let sheet = Application.ActiveSheet;
      // 使用Cells方法获取指定单元格，并设置其值
      sheet.Cells.Item(row, col).Value2 = text;
    }
  };
})();